﻿#include "tool_button.h"
#include <QStyle>
#include "easylogging++.h"

ToolButton::ToolButton(QWidget *parent)
    : QToolButton{parent}
{
    this->setProperty("status", "normal");
    connect(this, &QToolButton::toggled, this, [=](bool flag) {
        if (flag)
        {
            this->setProperty("status", "pressed");
        }
        else
        {
            this->setProperty("status", "hover");
        }

        style()->polish(this);
    });
}

#if QT_VERSION <= QT_VERSION_CHECK(5, 15, 2)
void ToolButton::enterEvent(QEvent *e)
#else
void ToolButton::enterEvent(QEnterEvent *e)
#endif
{
    bool checked = this->isChecked();
    if (!checked)
    {
        this->setProperty("status", "hover");
        style()->polish(this);
    }
}

void ToolButton::leaveEvent(QEvent *e)
{
    bool checked = this->isChecked();
    if (!checked)
    {
        this->setProperty("status", "normal");
        style()->polish(this);
    }
}
